package org.example.controller;


import org.example.entity.Order;
import org.example.mapper.OrderMapper;
import org.example.service.AircraftService;
import org.example.service.IBoatService;
import org.example.service.IPubService;
import org.example.service.OrderService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api")
@MapperScan("com.alipaydemo.dao")
public class ApiController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private AircraftService aircraftService;

    @Autowired
    private IBoatService boatService;

    @Autowired
    private IPubService pubService;


    @Transactional
    @PostMapping("/buy")
    public boolean buy(Integer orderId,Integer type) {
        Order order=new Order();
        switch (type){
            case 1:
                aircraftService.getById(orderId);

                break;
            case 2:
                break;
            case 3:

        }

return false;


    /*    Goods goods = goodsMapper.selectById(goodsId);
        int store = goods.getStore() - 1;
        if (store < 0) {
            return false;
        }
        goods.setStore(store);

        Date date = new Date();
        Orders orders = new Orders();
        orders.setGoodsId(goodsId);
        orders.setCreateTime(date);
        orders.setState("未支付");
        orders.setName("购买" + goods.getName() + "订单");
        orders.setOrderId(new SimpleDateFormat("yyyyMMdd").format(date) + System.currentTimeMillis());
        orders.setTotal(goods.getPrice().multiply(BigDecimal.ONE));

        return ordersMapper.insert(orders) > 0 &&  goodsMapper.updateById(goods) > 0;*/
    }
}
